home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / drdobbs / 1987 / 11 / getpixel.c < prev    next >
C/C++ Source or Header  |  1987-10-08  |  2KB  |  68 lines

  1. /*-------------------------------------------------------------------------
  2.     getpixel.c
  3.     Returns the value of pixel h, v in the bitmap "bmap".
  4.     Written in 68000 inline assembly both because it is faster
  5.     and because it is quite easy to do.  A version of this code
  6.     was used by Mike Morton in his StarFlight program.
  7.     
  8.     This version has the following limitations:
  9.     
  10.     1.  It assumes that the cursor will not be in the way,
  11.     i.e. it has either been hidden or we are looking at an off-screen
  12.     bitmap.  In the contour map algorithm we are looking at an
  13.     off-screen bitmap.
  14.     
  15.     2.  This version also assumes that the coordinates at the upper left
  16.     are (0,0). Any offset to the coordinate system (by a call to SetOrigin)
  17.     is ignored.
  18.     
  19.     3.  This code will probably not work on the screen buffer for large screen
  20.     Macs, color Macs, gray scale Macs, etc.  It works fine on off-screen bitmaps
  21.     on my Mac II, as long as the depth is 1 bit per pixel.
  22.         
  23.     William May
  24.     303A Ridgefield Circle
  25.     Clinton, MA 01510
  26.     
  27.     Created:    1/20/87
  28.     Modified:    3/21/87        Found a bug: getpixel wouldn't handle
  29.                             bitmaps > 32K.
  30.   ------------------------------------------------------------------------*/
  31.  
  32. #include <QuickDraw.h>
  33. #include <asm.h>
  34.  
  35. #include "getpixel.h"
  36.  
  37. int getpixel(h, v, bmap)
  38. int h, v;
  39. BitMap *bmap;
  40. {
  41.     asm {
  42.         move.w    v,d0                ; load v and h into registers
  43.         ext.l    d0
  44.         move.w    h,d1
  45.         ext.l    d1
  46.         move.w    d1,d2                ; copy h coord for bit offset
  47.                                     ; only need low order byte
  48.  
  49.         move.l    bmap,a0                ; point to bitmap
  50.         
  51.         mulu    OFFSET(BitMap,rowBytes)(a0),d0
  52.                                     ; v * rowbytes is offset to row
  53.         lsr.l    #3,d1                ; extract byte offset
  54.         add.l    d1,d0
  55.         not.b    d2                    ; make bit number 68000 style
  56.         move.l    OFFSET(BitMap,baseAddr)(a0),a0
  57.                                     ; get base address of bitmap
  58.         add.l    d0,a0                ; get to the correct byte
  59.         btst    d2,(a0)                ; test the bit
  60.         beq        @0
  61.         
  62.         moveq    #1,d0                ; set value to 1
  63.         return
  64. @0
  65.         moveq    #0,d0                ; set value to 0
  66.     }
  67. }
  68.